-
Notifications
You must be signed in to change notification settings - Fork 73
[Bugfix] Fix JWT Secret Tail characters #1867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
bc9ded2
to
fcdfb59
Compare
fcdfb59
to
693c92c
Compare
315ccaa
to
0209639
Compare
701bb68
to
c19a0ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the JWT secret handling to use a fixed-size Secret
abstraction, adds trimming/filling of secret byte slices, and replaces direct JWT calls with a unified Secret
/Claims
API throughout the codebase.
- Introduce
Secret
interface and implementations (secret
,Secrets
,emptySecret
,secretSet
) with trimming/filling toDefaultTokenSecretSize
- Update token parsing/signing in
pkg/util/token
and callers to useClaims.Sign
andSecret.Validate
- Add extensive tests in
token_test.go
for trimming, filling, and prefix/postfix removal behaviors
Reviewed Changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
pkg/util/token/token.go | New Validate and token type wrapping with fixed-size secrets |
pkg/util/token/secret.go | Trim/fill logic for secrets, NewSecretWithSize implementation |
pkg/util/token/secrets.go | Secrets collection type and validation over a set |
pkg/util/token/secret_set.go | secretSet combining primary and secondary secrets |
pkg/util/token/secret_empty.go | Empty secret stub |
pkg/util/token/mods.go | Updated modifiers signature to util.ModR |
pkg/util/token/claims.go | Claims builder and .Sign method |
pkg/util/token/interface.go | Introduced Secret and Token interfaces |
pkg/util/token/consts.go | JWT claim constants |
pkg/util/token/method.go | Default JWT signing method |
pkg/util/token/token_test.go | New tests covering trimming, filling, prefix/postfix behavior |
pkg/util/mod.go | Moved emptyModR and updated ApplyModsR |
pkg/util/k8sutil/secrets.go | Added GetTokenSecret overloads |
Multiple callers (k8sutil, arangod, backup handlers, deployment resources, CLI, integration) | Switched to Claims.Sign and Secret.Validate usage |
Comments suppressed due to low confidence (1)
pkg/util/token/token_test.go:207
- [nitpick] The test name "Ensure token gets trimmed" is used twice; consider renaming one of them to clearly distinguish the scenarios.
t.Run("Ensure token gets trimmed", func(t *testing.T) {
) | ||
|
||
type Mod func(in Claims) Claims | ||
func Validate(t string, secret []byte) (Token, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enforce the expected signing algorithm in Validate
by adding jwt.WithValidMethods(jwt.SigningMethodHS256.Alg()) (or a similar option) to jwt.Parse to avoid accepting tokens signed with none or other algorithms.
Copilot uses AI. Check for mistakes.
|
||
return !equality.Semantic.DeepDerivative(tokenClaims, exporterTokenClaims), true, nil | ||
return !equality.Semantic.DeepDerivative(tokenClaims, expectedClaims), true, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the actual claims map, not the Token interface, to DeepDerivative. For example:
return !equality.Semantic.DeepDerivative(tokenClaims.Claims(), expectedClaims), true, nil
return !equality.Semantic.DeepDerivative(tokenClaims, expectedClaims), true, nil | |
return !equality.Semantic.DeepDerivative(tokenClaims.Claims(), expectedClaims), true, nil |
Copilot uses AI. Check for mistakes.
No description provided.